package com.example.commuity.adapter.provider

import androidx.databinding.DataBindingUtil
import com.blankj.utilcode.util.ScreenUtils
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.commuity.R
import com.example.commuity.adapter.RecommendItemType
import com.example.commuity.databinding.ItemRecommendFollowItemViewBinding
import com.example.commuity.entity.viewdata.RecommendFollowViewData
import com.example.entity.BaseEntity

/**
 * 推荐瀑布流适配器
 * */
class RecommendFollowAdapter :BaseItemProvider<BaseEntity>() {


    override val itemViewType: Int=RecommendItemType.COMMUNITY_CARD_VIEW
    override val layoutId: Int= R.layout.item_recommend_follow_item_view

    override fun onViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        DataBindingUtil.bind<ItemRecommendFollowItemViewBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: BaseEntity) {
        var binding =helper.getBinding<ItemRecommendFollowItemViewBinding>()

        if (item!=null && binding!=null){
            var entity =item as RecommendFollowViewData
            var itemWith = ScreenUtils.getScreenWidth()/2
            var scale = itemWith*1.0f/entity.imgWidth

           var layoutParams= binding.ivCoverBg.layoutParams

            layoutParams.height = (entity.imgHeight *scale) .toInt()
            //重新设置加载布局
            binding.ivCoverBg.layoutParams=layoutParams
            //绑定数据
            binding.viewData=entity
            binding.executePendingBindings()
        }
    }
}